package com.example.myapplication.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;


import com.example.myapplication.adapters.NewsAdapter;
import com.example.myapplication.models.News;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class NewsFragment extends Fragment {
    private ListView newsListView;
    private NewsAdapter newsAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_news, container, false);
        initViews(view);
        setupNews();
        return view;
    }

    private void initViews(View view) {
        newsListView = view.findViewById(R.id.news_list_view);
    }

    private void setupNews() {
        List<News> newsList = new ArrayList<>();
        newsList.add(new News(R.drawable.ic_launcher_foreground, "人工智能新突破", "最新AI技术改变传统行业格局..."));
        newsList.add(new News(R.drawable.ic_launcher_foreground, "移动开发趋势", "2024年移动开发最新技术趋势分析..."));
        newsList.add(new News(R.drawable.ic_launcher_foreground, "在线教育发展", "疫情后在线教育行业的发展与变革..."));
        newsList.add(new News(R.drawable.ic_launcher_foreground, "编程语言排行", "2024年最受欢迎的编程语言TOP10..."));

        newsAdapter = new NewsAdapter(getActivity(), newsList);
        newsListView.setAdapter(newsAdapter);
    }
}